



// 封装一个get请求的方法
function HttpRequest (url, data, method = 'GET') {
 return new Promise(function (resolve, reject) {
  var XHR = XMLHttpRequest ? new XMLHttpRequest() : new window.ActiveXObject('Microsoft.XMLHTTP');
  XHR.onreadystatechange = function () {
   if (XHR.readyState == 4) {
    if ((XHR.status >= 200 && XHR.status < 300)) {
     var response = JSON.parse(XHR.responseText);
     resolve(response);
    } else {
     var err = JSON.parse(XHR.responseText);
     reject(err);
    }
   }
  }
  XHR.open('POST', url, true);
  XHR.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
  if (method == 'GET') {
   XHR.send(data);
  } else {

   XHR.send(JSON.stringify(data));
  }
 })
}